*********************************************
* This dofile creates the main tables for the paper titled: 
* THE GLOBAL SOURCING OF GREEN PRODUCTS
*********************************************

set more off
cap log close
clear 

/// if not already installed, please install the programs below
ssc install ftools 
ssc install reghdfe 
ssc install ivreg2
ssc install ivreghdfe 


log using "Green_Sourcing.log", replace
use "Green_Sourcing.dta", clear


* Set up definitions
local dv "ln_value"
local con "ln_gdp_pc_lag ln_pop_lag grth_lag expgdp_lag fdigdp_lag cpt_lag polcon4_lag ipr_index_lag patent_pop_lag gr_patent_pop_lag cnBITS_lag adv_plug missing_adv"
local fe "ctpr impexp year"
local fealt "ctpr impexp ctyr"
local cluster "cluster(ctpr ctyr)"


* T2
eststo clear
*Column 1 of T2
eststo: reghdfe `dv' c.lEPI, absorb(`fe') `cluster'
*Column 2 of T2
eststo: reghdfe `dv' c.lEPI##i.green_any, absorb(`fe') `cluster'
*Column 3 of T2
eststo: reghdfe `dv' c.lEPI##i.green_any `con', absorb(`fe') `cluster'
*Column 4 of T2
eststo: reghdfe `dv' c.lEPI##i.green_any `con', absorb(`fealt') `cluster'
*Column 5 of T2
eststo: reghdfe `dv' c.lEPI##i.green_any c.gr_patent_pop_lag##i.green_any `con', absorb(`fe') `cluster'
*Column 6 of T2
eststo: reghdfe `dv' i.climate_law_lag##i.green_any `con', absorb(`fe') `cluster'
*Column 7 of T2
eststo: reghdfe `dv' c.inv_so2_lag##i.green_any `con', absorb(`fe') `cluster'
*Column 8 of T2: Note can take a long time to estimate
eststo: ivreghdfe `dv' `con' (lEPI  lEPI_X_green = nclEPI nclEPI_X_green), absorb(`fe') `cluster'
*Column 9 of T2: Note can take a long time to estimate
eststo: ivreghdfe `dv' `con' (lEPI  lEPI_X_green = kyoto_lag kyoto_lag_X_green), absorb(`fe') `cluster'
*Output T2
esttab * using "T2.csv", b(%9.3f) p(%9.3f) brackets nostar scalar(r2_a beta1_plus_beta3 se_beta1_plus_beta3 F) nogaps csv replace

* T3
eststo clear
*Column 1 of T3
eststo: reghdfe `dv' c.lEPI##i.green_any `con' if consumer==1,  absorb(`fe') `cluster'
lincom _b[c.lEPI] + _b[c.lEPI#1.green_any]
estadd scalar beta1_plus_beta3 = r(estimate)
estadd scalar se_beta1_plus_beta3 = r(se)
estadd scalar p_beta1_plus_beta3 = r(p)
*Column 2 of T3
eststo: reghdfe `dv'c.lEPI##i.green_any `con' if indsup==1,  absorb(`fe') `cluster'
lincom _b[c.lEPI] + _b[c.lEPI#1.green_any]
estadd scalar beta1_plus_beta3 = r(estimate)
estadd scalar se_beta1_plus_beta3 = r(se)
estadd scalar p_beta1_plus_beta3 = r(p)
*Column 3 of T3
eststo: reghdfe `dv' c.lEPI##i.green_any `con' if cap_noauto==1,  absorb(`fe') `cluster'
lincom _b[c.lEPI] + _b[c.lEPI#1.green_any]
estadd scalar beta1_plus_beta3 = r(estimate)
estadd scalar se_beta1_plus_beta3 = r(se)
estadd scalar p_beta1_plus_beta3 = r(p)
*Column 4 of T3
eststo: reghdfe `dv' c.lEPI##i.green_any `con' if auto==1,  absorb(`fe') `cluster'
lincom _b[c.lEPI] + _b[c.lEPI#1.green_any]
estadd scalar beta1_plus_beta3 = r(estimate)
estadd scalar se_beta1_plus_beta3 = r(se)
estadd scalar p_beta1_plus_beta3 = r(p)
*Column 5 of T3
eststo: reghdfe `dv' c.lEPI##i.green_any `con' if high_member_panel==1, absorb(`fe') `cluster'
lincom _b[c.lEPI] + _b[c.lEPI#1.green_any]
estadd scalar beta1_plus_beta3 = r(estimate)
estadd scalar se_beta1_plus_beta3 = r(se)
estadd scalar p_beta1_plus_beta3 = r(p)
*Column 6 of T3
eststo: reghdfe `dv' c.lEPI##i.green_any `con' if high_member_panel==0, absorb(`fe') `cluster'
lincom _b[c.lEPI] + _b[c.lEPI#1.green_any]
estadd scalar beta1_plus_beta3 = r(estimate)
estadd scalar se_beta1_plus_beta3 = r(se)
estadd scalar p_beta1_plus_beta3 = r(p)
*Column 7 of T3
eststo: reghdfe `dv' c.lEPI##i.green_any `con' if hi_avgNGOpc==1, absorb(`fe') `cluster'
lincom _b[c.lEPI] + _b[c.lEPI#1.green_any]
estadd scalar beta1_plus_beta3 = r(estimate)
estadd scalar se_beta1_plus_beta3 = r(se)
estadd scalar p_beta1_plus_beta3 = r(p)
*Column 8 of T3
eststo: reghdfe `dv' c.lEPI##i.green_any `con' if hi_avgNGOpc==0, absorb(`fe') `cluster'
lincom _b[c.lEPI] + _b[c.lEPI#1.green_any]
estadd scalar beta1_plus_beta3 = r(estimate)
estadd scalar se_beta1_plus_beta3 = r(se)
estadd scalar p_beta1_plus_beta3 = r(p)
esttab * using "T3.csv", b(%9.3f) p(%9.3f) brackets nostar scalar(r2_a beta1_plus_beta3 se_beta1_plus_beta3 F) nogaps csv replace


log close
